<?php
	//No direct access
	defined('_JEXEC') or die('Restricted access');
?>
<script language="javascript" type="text/javascript">
<!--
	/**
	* Default function.  Usually would be overriden by the component
	*/
	function submitbutton(pressbutton) {
		
		var form = document.adminForm;

		if(pressbutton == 'delete') {
			if (form.boxchecked.value == 0){
				alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_TRANSACTIONS', true ); ?>" );
				return;
			} 
		}

		submitform(pressbutton);
	}

	/**
	* Submit the admin form
	*/
	function submitform(pressbutton){
		if (pressbutton) {
			document.adminForm.task.value=pressbutton;
		} else {
			document.adminForm.task.value= '';
		}
		if (typeof document.adminForm.onsubmit == "function") {
			document.adminForm.onsubmit();
		}
		document.adminForm.submit();
	}
//-->
</script>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">
			<h3><?php echo $this->params->get('page_title'); ?></h3>
			<hr />
			<div id="toolbar">
				<a class="toolbar" onclick="submitbutton('delete');" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_DELETE'); ?>" class="icon-32-delete"></span>
					<?php echo JText::_('OWNSERVICE_DELETE'); ?>
				</a>
				<a class="toolbar" onclick="javascript:if(document.adminForm.boxchecked.value==0){alert('<?php echo JText::_('Please first make a selection from the list'); ?>');}else{submitbutton('download');}" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>" class="icon-32-export"></span>
					<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>
				</a>
				<a class="toolbar" onclick="submitbutton('cancel');" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_CLOSE'); ?>" class="icon-32-cancel"></span>
					<?php echo JText::_('OWNSERVICE_CLOSE'); ?>
				</a>
			</div>
			<div class="clear"> </div>
			<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm" autocomplete="off">
				<table>
					<tr>
						<td><?php echo JText::_('OWNSERVICE_DATE'); ?> :</td>
						<td>
							<?php list($y, $m, $d)	= explode('-',$this->lists['date']); echo $d.'-'.$m.'-'.$y; ?>
						</td>
					</tr>
				</table>
				<table>
				<tr>
					<td width="100%">
						<?php echo JText::_( 'OWNSERVICE_FILTER' ); ?>:<input type="text" name="search" value="<?php echo htmlspecialchars($this->lists['search']);?>"  onchange="document.adminForm.submit();" />
						<button onclick="this.form.submit();" class="button">
							<?php echo JText::_( 'Go' ); ?>
						</button>
						<button onclick="document.adminForm.search.value='';document.adminForm.filter_branch.value='';this.form.submit();" class="button">
							<?php echo JText::_( 'Reset' ); ?>
						</button>
					</td>
					<td nowrap="nowrap">
						<?php if( isset($this->lists['status']) ) :?>
								<?php echo $this->lists['status']; ?>
						<?php endif; ?>
						<?php if( isset($this->lists['branch']) ) :?>
								<?php echo $this->lists['branch']; ?>
						<?php endif; ?>
					</td>
				</tr>
				</table>
				<table class="adminlist" cellspacing="1">
				<thead>
				<tr>
					<td align="center" class="tablelist">
						<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->rows); ?>);" />
					</td>
					<td align="center" class="tablelist">
						<?php echo  JHTML::_('grid.sort',  'OWNSERVICE_RECEIVER_NO', 't.invoice', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort',  'OWNSERVICE_USER', 'u.username', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort',  'OWNSERVICE_ACCOUNT_NO', 't.account', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort', 'OWNSERVICE_BANK_NAME', 'a.bank_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort', 'OWNSERVICE_BRANCH_CITY', 'a.branch_city', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort',  'OWNSERVICE_CREATE_DATE', 't.created', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort',  'OWNSERVICE_AMOUNT_TRANSFER', 't.amount', $this->lists['order_Dir'], $this->lists['order'] ); ?><br />(AUD)
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort',  'OWNSERVICE_RATE', 't.rate', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JHTML::_('grid.sort',  'OWNSERVICE_TOTAL_EXCHANGE', 't.total', $this->lists['order_Dir'], $this->lists['order'] ); ?><br />(THB)
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_STATUS'); ?>
					</td>
				</tr>
				</thead>
				<tfoot>
					<tr>
						<td colspan="12"><?php echo $this->pageNav->getListFooter(true); ?></td>
					</tr>
				</tfoot>
				<tbody>
					<?php
					$priceformat 	= OwnserviceHelper::getParams('price_format', '#,###.##');
					$dateformat  	= OwnserviceHelper::getParams('date_format', '%d/%m/%Y');
					for($i=0,$n=count($this->rows);$i<$n;$i++):
					$row				= $this->rows[$i];
					$checked		= JHTML::_('grid.checkedout', $row, $i );
					?>
					<tr class="<?php echo "row$k"; ?>">
						<td align="center" class="inner_tablelist">
							<?php echo $checked; ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo $row->invoice; ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo $row->username; ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo OwnserviceHelper::accountFormat($row->account); ?>
						</td>
						<td class="inner_tablelist">
							<?php if($row->bank_name=='other'): ?>
								<?php echo $row->bank_other; ?>
							<?php else: ?>
								<?php echo $row->bank_name; ?>
							<?php endif; ?>
						</td>
						<td class="inner_tablelist"> 
							<?php echo $row->branch_city; ?>	
						</td>
						<td class="inner_tablelist" align="center">
							<?php echo JHTML::_('date', $row->created, $dateformat); ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount);  ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php
								$color = '';
								if($row->extrarate > 0.00 ) {
									$color = 'red';
								} else if($row->extrarate < 0.00) {
									$color = 'green';
								}
							?>
							<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px solid;">
								<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th); ?> THB
							</div>
							<?php endif; ?>
							<div>
								<span class ="<?php echo $color; ?>">
								<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate); ?>
								</span>
								<?php echo $row->rate_code; ?> 
							</div>
						</td>
						<td align="center" class="inner_tablelist">
							<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px solid;">
								<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
							</div>
							<?php endif; ?>
							<div>
							<span class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
								<?php 
									if($row->extratotal > 0.00) {
										echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal);
									} else {
										echo OwnserviceHelper::moneyFormat($priceformat,( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))); 
									}
								?>
								</span> <?php echo $row->rate_code; ?>
							</div>
						</td>
						<td align="center" class="inner_tablelist"><?php echo OwnserviceHelper::getState($row->state); ?></td>
					</tr>
					<?php endfor; ?>
				</tbody>
				</tbody>
			</table>
			
			<input type="hidden" name="boxchecked" value="0" />
			<input type="hidden" name="id" value="" />
			<input type="hidden" name="option" value="com_ownservice" />
			<input type="hidden" name="task" value="" />
			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
			<input type="hidden" name="controller" value="transactionall" />
			<input type="hidden" name="view" value="transactionall" />
			<input type="hidden" name="layout" value="transfers" />
			<input type="hidden" name="date" value="<?php echo $this->lists['date']; ?>" />
			<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
			<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
			<?php echo JHTML::_( 'form.token' ); ?>
			</form>
	</div>
</div>